//这个引入不生效，@types里缺少此文件夹
import {fileURLToPath, URL} from 'node:url'

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
// import {fileURLToPath, URL} from 'url'

import {viteMockServe} from 'vite-plugin-mock'

// 用于按需引入element-plus组件
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
    base: './',
    plugins: [
        vue({
            script: {
                defineModel: true
            }
        }),
        viteMockServe(viteMockServe({
            mockPath: 'mock'
        })),
        AutoImport({
            imports: ['vue', 'vue-router', 'pinia'], // 自动导入的依赖库数组
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        })
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    server: {
        host:  '0.0.0.0',
        port: '8808',
        hmr: true // 热更新
    },
    css: {
        preprocessorOptions: {
            // scss预编译程序
            scss: {
                additionalData: '@use "./src/assets/scss/base/mixin.scss" as *;'
            }
        }
    }
})
